package com.mmd.redis;

import com.mmd.utils.SerializeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.*;
import redis.clients.jedis.params.geo.GeoRadiusParam;

import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.util.*;


public abstract class BaseRedisCache {
    private static Logger log = LoggerFactory.getLogger(BaseRedisCache.class);
    protected JedisPool pool = null;

    public BaseRedisCache() {
    }

    public abstract void initPool();

    public JedisPool getPool() {
        if (this.pool == null) {
            this.initPool();
        }

        return this.pool;
    }

    public void returnResource(JedisPool pool, Jedis redis) {
        if (redis != null) {
            redis.close();
        }

    }

    public void set(String key, Object value) {
        this.set(key, value, 0);
    }

    public void expire(String key, int exp_time) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.expire(key.getBytes(), exp_time);
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void delete(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.del(key.getBytes());
        } catch (Exception var8) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var8);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void zdelete(String key, String member) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.zrem(key.getBytes(), new byte[][]{member.getBytes()});
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void zadd(String key, double score, String member, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.zadd(key.getBytes(), score, member.getBytes());
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }
        } catch (Exception var12) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var12);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void zadd(String key, double score, String member) {
        this.zadd(key, score, member, 0);
    }

    public Double zscore(String key, String member) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Double var5 = jedis.zscore(key.getBytes(), member.getBytes());
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public void zincrby(String key, double score, String member, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.zincrby(key.getBytes(), score, member.getBytes());
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }
        } catch (Exception var12) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var12);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void sadd(String key, String val, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.sadd(key, new String[]{val});
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void sadd(int expire, String key, String... members) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.sadd(key, members);
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void srem(String key, String... members) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.srem(key, members);
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public Set<String> smembers(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Set var4 = jedis.smembers(key);
            return var4;
        } catch (Exception var8) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var8);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public void zincrby(String key, long score, String member) {
        this.zincrby(key, (double)score, member, 0);
    }

    public Set zrevrank(String key, int start, int end) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Set var6 = jedis.zrevrange(key.getBytes(), (long)start, (long)end);
            return var6;
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Long zrevrank(String key, String member) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Long var5 = jedis.zrevrank(key.getBytes(), member.getBytes());
            return var5;
        } catch (Exception var9) {
            log.error(" zrevrank 出错了，pool->" + pool + " jedis->" + jedis + " e->", var9);
            this.returnBrokenResource(pool, jedis);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    private void returnBrokenResource(JedisPool pool, Jedis jedis) {
        if (pool != null && jedis != null) {
            pool.returnBrokenResource(jedis);
        }

    }

    public Set zrangeByScore(String key, double min, double max) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Set var8 = jedis.zrangeByScore(key, min, max);
            return var8;
        } catch (Exception var12) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var12);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public void incr(String key, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.incr(key.getBytes());
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public Long reIncr(String key, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;
        Long keyValue = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            keyValue = jedis.incr(key.getBytes());
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

        return keyValue;
    }

    public Long incrby(String key, long increment, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            long result = jedis.incrBy(key.getBytes(), increment);
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }

            Long var9 = result;
            return var9;
        } catch (Exception var13) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var13);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Boolean exists(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Boolean var4 = jedis.exists(key);
            return var4;
        } catch (Exception var8) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var8);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Long reIncrby(String key, long increment, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;
        Long keyValue = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            keyValue = jedis.incrBy(key.getBytes(), increment);
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }
        } catch (Exception var12) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var12);
        } finally {
            this.returnResource(pool, jedis);
        }

        return keyValue;
    }

    public void set(String key, Object value, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.set(key.getBytes(), SerializeUtil.serialize(value));
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void setUnserialize(String key, Object value, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public Long setnx(String key, Object value) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Long var5 = jedis.setnx(key.getBytes(), SerializeUtil.serialize(value));
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Object getSet(String key, Object value) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Object var5 = SerializeUtil.unserialize(jedis.getSet(key.getBytes(), SerializeUtil.serialize(value)));
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Object get(String key) {
        return this.get(key.getBytes());
    }

    public Object get(byte[] key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            byte[] data = jedis.get(key);
            Object var5 = SerializeUtil.unserialize(data);
            return var5;
        } catch (Exception var9) {
            log.error("get ex,key:{}", new String(key), var9);
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public void setList(String key, String value) {
        this.setList(key, (String)value, 0);
    }

    public void setList(String key, String value, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.lpush(key, new String[]{value});
            if (expire > 0) {
                jedis.expire(key, expire);
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void setList(String key, Object value) {
        this.setList(key, (Object)value, 0);
    }

    public void setList(String key, Object value, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.lpush(key.getBytes(), new byte[][]{SerializeUtil.serialize(value)});
            if (expire > 0) {
                jedis.expire(key.getBytes(), expire);
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public Long lpush(String key, String value) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Long var5 = jedis.lpush(key, new String[]{value});
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Long rpush(String key, String value) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Long var5 = jedis.rpush(key, new String[]{value});
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public List<String> brpop(String key, int timeOut) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            List<String> strs = new ArrayList();
            strs.add(key);

            while(true) {
                String ss = jedis.rpop(key);
                if (ss != null) {
                    strs.add(ss);
                    ArrayList var15 = (ArrayList) strs;
                    return var15;
                }

                Random r = new Random();
                long ll = (long)r.nextInt(100) + 10L;
                Thread.sleep(ll);
            }
        } catch (Exception var13) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var13);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public List<String> blpop(String key, int timeOut) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            List<String> strs = new ArrayList();
            strs.add(key);

            while(true) {
                String ss = jedis.lpop(key);
                if (ss != null) {
                    strs.add(ss);
                    ArrayList var15 = (ArrayList) strs;
                    return var15;
                }

                Random r = new Random();
                long ll = (long)r.nextInt(300) + 10L;
                Thread.sleep(ll);
            }
        } catch (Exception var13) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var13);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Long ttl(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Long var4 = jedis.ttl(key);
            return var4;
        } catch (Exception var8) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var8);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public List<Object> getList(String key) {
        JedisPool pool = null;
        Jedis jedis = null;
        ArrayList resList = new ArrayList();

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            List<byte[]> byteList = jedis.lrange(key.getBytes(), 0L, -1L);

            for(int i = 0; i < byteList.size(); ++i) {
                resList.add(SerializeUtil.unserialize((byte[])byteList.get(i)));
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

        return resList;
    }

    public <T> List<T> getListByType(String key) {
        JedisPool pool = null;
        Jedis jedis = null;
        ArrayList resList = new ArrayList();

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            List<byte[]> byteList = jedis.lrange(key.getBytes(), 0L, -1L);

            for(int i = 0; i < byteList.size(); ++i) {
                resList.add(SerializeUtil.unserialize((byte[])byteList.get(i)));
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

        return resList;
    }

    public void ldelete(String key, Object value, int count) {
        this.ldelete(key.getBytes(), value, count);
    }

    public Object rpop(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            byte[] var4 = jedis.rpop(key.getBytes());
            return var4;
        } catch (Exception var8) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var8);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public void ldelete(byte[] key, Object value, int count) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.lrem(key, (long)count, SerializeUtil.serialize(value));
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public Long ldelete(String key, String value, int count) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Long var6 = jedis.lrem(key, (long)count, value);
            return var6;
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

        return 0L;
    }

    public long getSize(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            long var4 = jedis.zcard(key.getBytes());
            return var4;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return 0L;
    }

    public void hset(String key, String field, String value) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.hset(key, field, value);
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void hset(String key, String field, Object value) {
        this.hset(key, field, value, 0);
    }

    public void hset(String key, String field, Object value, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.hset(key.getBytes(), field.getBytes(), SerializeUtil.serialize(value));
            if (expire > 0) {
                jedis.expire(key, expire);
            }
        } catch (Exception var11) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var11);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void hmset(String key, Map map) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.hmset(key, map);
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public String hget(String key, String field) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            String var5 = jedis.hget(key, field);
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Long hdel(String key, String field) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Long var5 = jedis.hdel(key, new String[]{field});
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Object hgetObject(String key, String field) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Object var5 = SerializeUtil.unserialize(jedis.hget(key.getBytes(), field.getBytes()));
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public int hlen(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            int var4 = Integer.parseInt(jedis.hlen(key).toString());
            return var4;
        } catch (Exception var8) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var8);
        } finally {
            this.returnResource(pool, jedis);
        }

        return 0;
    }

    public boolean hexists(String key, String field) {
        boolean isexit = false;
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            isexit = jedis.hexists(key, field);
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

        return isexit;
    }

    public Set<String> hkeys(String key) {
        Set<String> array = null;
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            array = jedis.hkeys(key);
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return array;
    }

    public boolean sismember(String key, String member) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            boolean var5 = jedis.sismember(key, member);
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return false;
    }

    public void hincrby(String key, String field, long num, int exptime) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.hincrBy(key, field, num);
            if (exptime > 0) {
                jedis.expire(key.getBytes(), exptime);
            }
        } catch (Exception var12) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var12);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public Object getListL(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            byte[] data = jedis.lpop(key.getBytes());
            Object var5 = SerializeUtil.unserialize(data);
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public long getListLen(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            long data = jedis.llen(key.getBytes());
            long var6 = data;
            return var6;
        } catch (Exception var11) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var11);
        } finally {
            this.returnResource(pool, jedis);
        }

        return 0L;
    }

    public void setListR(String key, String value) {
        this.setListR(key, value, 0);
    }

    public void setListR(String key, String value, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.rpush(key.getBytes(), new byte[][]{SerializeUtil.serialize(value)});
            if (expire > 0) {
                jedis.expire(key, expire);
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public void lset(String key, Object value, int index) {
        this.lset(key, value, index, 0);
    }

    public void lset(String key, Object value, int index, int expire) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.lset(key.getBytes(), (long)index, SerializeUtil.serialize(value));
            if (expire > 0) {
                jedis.expire(key, expire);
            }
        } catch (Exception var11) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var11);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public List<Object> getList(String key, int start, int end) {
        JedisPool pool = null;
        Jedis jedis = null;
        ArrayList resList = new ArrayList();

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            List<byte[]> byteList = jedis.lrange(key.getBytes(), (long)start, (long)end);

            for(int i = 0; i < byteList.size(); ++i) {
                resList.add(SerializeUtil.unserialize((byte[])byteList.get(i)));
            }
        } catch (Exception var12) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var12);
        } finally {
            this.returnResource(pool, jedis);
        }

        return resList;
    }

    public List<String> getListStr(String key, int start, int end) {
        JedisPool pool = null;
        Jedis jedis = null;
        ArrayList resList = new ArrayList();

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            List<byte[]> byteList = jedis.lrange(key.getBytes(), (long)start, (long)end);

            for(int i = 0; i < byteList.size(); ++i) {
                resList.add(new String((byte[])byteList.get(i)));
            }
        } catch (Exception var12) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var12);
        } finally {
            this.returnResource(pool, jedis);
        }

        return resList;
    }

    public Object getRpop(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Object var4 = SerializeUtil.unserialize(jedis.rpop(key.getBytes()));
            return var4;
        } catch (Exception var8) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var8);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Object getLpop(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Object var4 = SerializeUtil.unserialize(jedis.lpop(key.getBytes()));
            return var4;
        } catch (Exception var8) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var8);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Long publish(String channel, Object message) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(message);
            String msg1 = baos.toString("ISO-8859-1");
            Long var8 = jedis.publish(channel.getBytes(), msg1.getBytes());
            return var8;
        } catch (Exception var12) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var12);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public void subscribe(JedisPubSub jedisPubSub, String... channels) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            jedis.subscribe(jedisPubSub, channels);
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public Set<String> sinter(String... keys) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Set var4 = jedis.sinter(keys);
            return var4;
        } catch (Exception var8) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var8);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public void batchDelete(String key) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Set<String> set = jedis.keys(key);
            Iterator it = set.iterator();

            while(it.hasNext()) {
                String keyStr = (String)it.next();
                log.info("删除key={}", keyStr);
                jedis.del(keyStr);
            }
        } catch (Exception var10) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var10);
        } finally {
            this.returnResource(pool, jedis);
        }

    }

    public Set<String> keys(String keys) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Set<String> set = jedis.keys(keys);
            Set var5 = set;
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Long geoadd(String key, GeoCoordinate coordinate, String memberName) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Long obj = jedis.geoadd(key, coordinate.getLongitude(), coordinate.getLatitude(), memberName);
            Long var7 = obj;
            return var7;
        } catch (Exception var11) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var11);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public List<GeoRadiusResponse> geoRadius(String key, GeoCoordinate coordinate, double radius) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            List var7 = jedis.georadius(key, coordinate.getLongitude(), coordinate.getLatitude(), radius, GeoUnit.KM, GeoRadiusParam.geoRadiusParam().withDist().withCoord().sortAscending());
            return var7;
        } catch (Exception var11) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var11);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    List<GeoRadiusResponse> georadiusByMember(String key, String member, double radius) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            List var7 = jedis.georadiusByMember(key, member, radius, GeoUnit.KM, GeoRadiusParam.geoRadiusParam().withDist().withCoord().sortAscending());
            return var7;
        } catch (Exception var11) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var11);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public Double geoDist(String key, String member1, String member2, GeoUnit unit) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            Double var7 = jedis.geodist(key, member1, member2, unit);
            return var7;
        } catch (Exception var11) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var11);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public List<String> geohash(String key, String... members) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            pool = this.getPool();
            jedis = pool.getResource();
            List var5 = jedis.geohash(key, members);
            return var5;
        } catch (Exception var9) {
            pool.returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource(pool, jedis);
        }

        return null;
    }

    public List<GeoCoordinate> geopos(String key, String... members) {
        JedisPool pool = null;
        Jedis jedis = null;

        try {
            jedis = ((JedisPool)pool).getResource();
            List var5 = jedis.geopos(key, members);
            return var5;
        } catch (Exception var9) {
            ((JedisPool)pool).returnBrokenResource(jedis);
            log.error("redis exception", var9);
        } finally {
            this.returnResource((JedisPool)pool, jedis);
        }

        return null;
    }

    public void initPool(int randomIndex) {
    }

    public void initPool(String ip, String port, String pwd) {
    }
}
